import { _decorator, Component, Node } from 'cc';
import {
    fly
} from './fly';
const { ccclass, property } = _decorator;

@ccclass('bg')
export class bg extends Component {

    @property
    speed:number = 4;

    @property
    width:number = 288;

    @property(fly)
    bird:fly = null!;

    //记录点击次数
    count:number = 0;

    start() {
        //监听点击
        for (const element of this.node.children) {
            element.on(Node.EventType.TOUCH_START,()=>{
                console.log("点击了");
                if(this.count>=10){
                    this.count = 10
                }
                this.bird.flyPlay(this.count++)
            })
        }
    }

    update(deltaTime: number) {
        for (const element of this.node.children) {
            element.setPosition(
                element.position.x - this.speed*deltaTime,
                element.position.y,element.position.z
            )
            //如果背景超出屏幕
            if(element.position.x<-this.width){
                element.setPosition(
                    element.position.x+this.width*2,
                    element.position.y,element.position.z
                )
            }
        }
    }
}


